#!/bin/ksh

fortran_compile=$FC
if [[ $FC = '' ]]
then echo "set an environment variable FC to the fortran_compile_command like f90"
     echo "or do all compilation first and comment the compilation lines"
     exit
fi

label=$1 ; rad=1200

if [[ ! -s BX.Ts.${label}.$rad ]]
then echo "BX.Ts.${label}.$rad not found"
     exit
fi

${fortran_compile} zonav.f -o zonav.exe

ln BX.Ts.${label}.$rad fort.11
zonav.exe > zonav.Ts.${label}.log
cp fort.10 work_files/ZON.Ts.${label}.1200.step1
rm fort.11     zonav.exe

${fortran_compile} annzon.f -o annzon.exe
annzon.exe  > annzon.Ts.${label}.log   ; rm annzon.exe
mv fort.96 ZonAnn.Ts.${label}.txt
mv fort.97 GLB.Ts.${label}.txt
mv fort.98 NH.Ts.${label}.txt
mv fort.99 SH.Ts.${label}.txt
mv fort.12 work_files/ZON.Ts.${label}.1200
mv fort.11 work_files/ANNZON.Ts.${label}.1200
rm fort.10
mkdir results 2> /dev/null
mv *txt results/.

